<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%-- 
    Document   : blank
    Created on : 19.11.2008, 15:33:27
    Author     : Cyclone
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<body>
    <script src="js/courses.js" type="text/javascript"></script>

    <%@include file="systemMessage.jsp" %>

    <div id="box" class="rounded-divcascade">
        <div id="rightnow">
            <h3 class="reallynow">
                <span>
                    Описание курса
                </span>
                <!--<a class="app_add" href="#addUser">Добавить пользователя</a>-->
                <br/>
            </h3>
        </div>

        <form id="form" action="EditCourse" method="post" class="rounded-formcascade" name="newcourse">
            <fieldset>
                <legend>Общее</legend>
                <label for="title">Название : </label>
                <c:choose><c:when test="${mayEdit}">
                        <input name="title" type="text"
                               tabindex="1" value="${fn:escapeXml(course.title)}" />
                    </c:when><c:otherwise>
                        <input type="text"
                               tabindex="1" value="${fn:escapeXml(course.title)}" readonly="readonly" />
                    </c:otherwise></c:choose>

                    <br />

                    <label for="directionId">Направление : </label>
                <c:choose><c:when test="${mayEdit}">
                        <select name="directionId" tabindex="2">
                            <c:forEach items="${directionList}" var="direction">
                                <c:choose><c:when test="${course.curriculumLevel.id == direction.id}">
                                        <option selected="selected" value="${direction.id}">${direction.title}</option>
                                    </c:when><c:otherwise>
                                        <option value="${direction.id}">${direction.title}</option>
                                    </c:otherwise></c:choose>
                            </c:forEach>
                        </select>
                    </c:when><c:otherwise>
                        <input type="text"
                               tabindex="2" value="${course.curriculumLevel.title}" readonly="readonly" />
                    </c:otherwise></c:choose>

                    <br />

                    <label for="number">Номер : </label>
                <c:choose><c:when test="${mayEdit}">
                        <input name="number" type="text"
                               tabindex="3" value="${course.numeral}" style="width: 210px;" />
                    </c:when><c:otherwise>
                        <input type="text"
                               tabindex="3" value="${course.numeral}" style="width: 210px;" readonly="readonly" />
                    </c:otherwise></c:choose>
                    <br />
                    <label for="description">Описание : </label>

                <c:choose><c:when test="${mayEdit}">
                        <textarea id="textAreaDescription" class="taWysiwyg" name="description" tabindex="4" style="height: 50px;" onmouseover="textAreaFocus();" onmouseout="textAreaBlur();">${course.description}</textarea>
                    </c:when><c:otherwise>
                        <textarea id="textAreaDescription" class="taWysiwyg" readonly="readonly" tabindex="4" style="height: 50px;" onmouseover="textAreaFocus();" onmouseout="textAreaBlur();">${course.description}</textarea>
                    </c:otherwise></c:choose>
                    <br/>
                    <a href="javascript:" class="goWysiwyg">форматировать текст</a>

                    <input name="courseId" type="hidden" value="${course.id}">

                <%--<c:if test="${sessionScope.roles.admin || sessionScope.roles.tutor}">--%>
                <%--<p align="center">--%>
                <div style="text-align: center">
                    <a href="SignStudents?courseId=${course.id}"><input style="width: 205px;" type="button" value="Студенты курса"></a>
                        <%--<c:if test="${sessionScope.roles.admin}">--%>
                    <a href="SignTutors?courseId=${course.id}"><input  style="width: 205px;" type="button" value="Тьюторы курса"></a>
                        <c:if test="${sessionScope.roles.admin || sessionScope.roles.tutor}">
                        <input  style="width: 205px;" type="button" value="Удалить курс" onclick="deleteCourse(${course.id});"/>
                    </c:if>
                </div>
                <%--</p>--%>
                <%--</c:if>--%>

            </fieldset>
                <br/>
            <fieldset>
                <legend>
                    <a name="labs">Практические работы курса</a>
                </legend>

                <c:set var="newNumber" value="1" />
                <%--                <c:choose><c:when test="${!empty labList}">--%>
                <c:choose><c:when test="${!empty course.labList}">


                        <table style="width: 100%;" id="labsTable">
                            <thead>
                                <tr>
                                    <c:if test='<%= request.isUserInRole("admin")%>'>
                                        <th width="20px">ID</th>
                                    </c:if>
                                    <th width="56px">№</th>
                                    <th>Название практической работы</th>
                                    <th width="90px">Операции</th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:forEach items="${course.labList}" var="lab">
                                    <c:set var="newNumber" value="${lab.numeral + 1}" />
                                    <tr>
                                        <c:if test='<%= request.isUserInRole("admin")%>'>
                                            <td>${lab.id}</td>
                                        </c:if>
                                        <td style="text-align: center;">
                                            <c:if test="${!empty lab.numeral}">
                                                <c:if test="${mayEdit}"><img src="img/icons/arrow_down_mini.gif" onclick="window.location = 'MoveCurriculum?id=${lab.id}&parentId=${course.id}&dir=down';" width="16" height="16" align="absmiddle" style="cursor: pointer;" alt="Вниз"/></c:if>
                                                ${lab.numeral}
                                                <c:if test="${mayEdit}"><img src="img/icons/arrow_up_mini.gif" onclick="window.location = 'MoveCurriculum?id=${lab.id}&parentId=${course.id}&dir=up';" width="16" height="16" align="absmiddle" style="cursor: pointer;" alt="Вверх"/></c:if>
                                            </c:if>
                                        </td>
                                        <td><a href="Lab?id=${lab.id}" title="Просмотреть описание практической работы">${lab.title}</a></td>
                                        <td style="padding: 0px;">
                                            <select onchange="labActionSelectChanged(event, ${lab.id}, '${lab.title}', 'Course?id=${course.id}');" style="width: 98%; margin: 0px; padding: 0px;">
                                                <option selected="selected">...</option>
                                                <optgroup label="Общие">
                                                    <option value="1">Описание</option>
                                                    <c:choose><c:when test="${sessionScope.roles.onlyStudent}">
                                                            <option value="2">Подробнее</option>
                                                        </c:when><c:otherwise>
                                                            <option value="2">Изменить</option>
                                                        </c:otherwise></c:choose>
                                                    <c:if test="${sessionScope.roles.tutor || sessionScope.roles.admin}">
                                                        <option value="5">Удалить</option>
                                                    </c:if>
                                                </optgroup>
                                            </select>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                        </table>
                    </c:when><c:otherwise>
                        Список практических работ пуст
                        <br />
                    </c:otherwise></c:choose>
                <c:if test="${sessionScope.roles.admin || sessionScope.roles.tutor}">
                    <br />
                    <input type="button" id="button1" value="Добавить практическую работу №${newNumber}" style="width: 50%;"
                           onclick="window.location = 'Labs?predefDirectionId=${course.curriculumLevel.id}&predefCourseId=${course.id}&predefNumber=${newNumber}#addLab'" />
                </c:if>
            </fieldset>


            <c:if test="${mayEdit || !empty course.documents}">
                <br/>
                <fieldset>
                    <legend>Приложения</legend>
                    <c:if test="${!empty course.documents}">
                        <ul style="display: block">
                            <c:forEach items="${course.documents}" var="document">
                                <li style="margin-left: 20px;">
                                    <a href="FileDownload?docId=${document.idDocument}">
                                        <%--
                                        <c:if test="${fn:contains(document.currentVersionContent.mime, 'image')}">
                                            Картинка:
                                        </c:if>
                                        --%>
                                        <img src="${document.currentVersionContent.iconUrl}" alt="Приложение"/>
                                        <span>${document.title}</span>
                                    </a>
                                    <%-- - <a href="#">(изменить)</a>--%>
                                    <%-- ${document.currentVersionContent --%>
                                </li>
                            </c:forEach>
                        </ul>
                    </c:if>

                    <c:if test="${sessionScope.roles.admin || sessionScope.admin.tutor}">

                        <input id="attachInput" type="button" value="Приложить файл" tabindex="5" style="width: 20%;" onclick="attachFile();"/>
                        <div id="attachDiv" style="display: none;">
                            <label for="attach">
                                Приложить файл
                            </label>
                            <input type="file" name="attach" tabindex="5" />

                            <label for="attachTitle">
                                Название приложения
                            </label>
                            <input type="text" name="attachTitle" tabindex="6" />
                        </div>
                    </c:if>
                </fieldset>
            </c:if>



            <c:if test="${mayEdit}">
                <br/>
                <fieldset>
                    <legend>Дополнительные свойства</legend>

                    <c:choose><c:when test="${!empty course.curriculumProperties}">
                            <table style="width: 100%;" id="labsTable">
                                <thead>
                                    <tr>
                                        <%-- <c:if test='<%= request.isUserInRole("admin")%>'>
                                            <th width="20px">ID</th>
                                        </c:if> --%>
                                        <th width="20px">ID</th>
                                        <th>Название свойства</th>
                                        <th width="90px">Операции</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <c:forEach items="${course.curriculumProperties}" var="property">
                                        <tr>
                                            <%-- <c:if test='<%= request.isUserInRole("admin")%>'>
                                                <td>${property.id.idAdditionalProperty}</td>
                                            </c:if> --%>
                                            <td>${property.id.idAdditionalProperty}</td>
                                            <td><a href="Property?propertyId=${property.id.idAdditionalProperty}">${property.additionalProperty.name}</a></td>
                                            <%--                                        <td><a href="Lab?id=${lab.id}" title="Просмотреть описание практической работы">${lab.title}</a></td> --%>
                                            <td style="padding: 0px;">
                                                <select onchange="propertyActionSelectChanged(event, ${course.id}, ${property.id.idAdditionalProperty}, '${fn:escapeXml(property.additionalProperty.name)}');" style="width: 98%; margin: 0px; padding: 0px;">
                                                    <option selected="selected" value="-1">...</option>
                                                    <optgroup label="Общие">
                                                        <option value="0">О свойстве</option>
                                                        <c:if test="${mayEdit}">
                                                            <option value="1">Удалить</option>
                                                        </c:if>
                                                    </optgroup>
                                                </select>
                                            </td>
                                        </tr>
                                        <c:if test="${property.additionalProperty.valueNeeded}">
                                            <tr>
                                                <td> </td>
                                                <td style="padding-bottom: 0px;">
                                                    <c:choose><c:when test="${!empty property.value}">
                                                            ${property.value}
                                                        </c:when><c:otherwise>
                                                            [значение не задано]
                                                        </c:otherwise></c:choose>
                                                    </td>
                                                    <td style="padding: 0px;">
                                                    <c:if test="${mayEdit}">
                                                        <input type="button" style="width: 100%; margin: 0px; padding-top: 2px; padding-bottom: 2px;" value="Задать" onclick="setProperty(event, ${course.id}, ${property.id.idAdditionalProperty}, '${fn:escapeXml(property.value)}')"/>
                                                    </c:if>
                                                </td>
                                            </tr>
                                        </c:if>
                                    </c:forEach>
                                </tbody>
                            </table>

                        </c:when><c:otherwise>
                            Дополнительные свойства отсутствуют
                            <br />
                        </c:otherwise></c:choose>
                    <c:if test="${mayEdit}">
                        <br />
                        <c:if test="${!empty propertyList}">
                            Добавить свойство:
                            <select onchange="if($(event.target).val() != -1 ) { window.location='EditCourse?courseId=${course.id}&act=addProp&propId='+$(event.target).val(); }">
                                <option selected="selected" value="-1">Выберите свойство...</option>
                                <c:forEach items="${propertyList}" var="property">
                                    <option value="${property.idAdditionalProperty}">${property.name}</option>
                                </c:forEach>
                            </select>
                        </c:if>
                        <%--
                                            <input type="button" id="button1" value="Добавить практическую работу №${newNumber}" style="width: 50%;"
                                                   onclick="window.location = 'Labs?predefDirectionId=${course.curriculumLevel.id}&predefCourseId=${course.id}&predefNumber=${newNumber}#addLab'" />
                        --%>
                    </c:if>

                </fieldset>
            </c:if>



            <div align="center">
                <c:choose>
                    <c:when test="${mayEdit}">
                        <input id="button1" type="submit" tabindex="20" value="Сохранить" />
                        <input id="button2" type="reset" tabindex="21" value="Отменить" /> <!-- onclick="window.location.reload();" />-->
                        <%--<input style="width: 205px;"type="button" tabindex="22" value="Удалить курс" onclick="deleteCourse(${course.id});"/>--%>
                        <br />

                        <a href="Courses"><input id="button2" type="button" tabindex="22" value="К списку курсов" /></a>
                        </c:when><c:otherwise>
                        <a href="Curriculum"><input id="button2" type="button" tabindex="22" value="К учебному журналу" /></a>
                        </c:otherwise></c:choose>

            </div>

        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            $("#liCourses").addClass("current");
            $('div#top-panel p').text('Свойства дистанционного курса');
        });
    </script>
</body>

